from PySide6.QtWidgets import QMenu,QMessageBox
from PySide6.QtGui import QDesktopServices,QPixmap

class HelpMenu(QMenu):
    """帮助菜单

    :param QMenu: PySide6 菜单类
    """
    def __init__(self):
        """初始化
        """
        super().__init__()
        self.setup_ui()
    
    def setup_ui(self):
        """初始化界面
        """
        # 设置按钮标题
        self.help_action = self.setTitle("帮助(&H)")

        # 查看帮助 发送反馈 分割符 关于记事本 
        self.view_help = self.addAction("查看帮助(&F)")
        self.send_feedback_action =   self.addAction("发送反馈(&A)")
        self.addSeparator()
        self.about_notepad =   self.addAction("关于记事本(&A)")

    def set_event_bind(self):
        """设置事件绑定
        """
        self.view_help.triggered.connect(self.get_help)
        self.send_feedback_action.triggered.connect(self.send_feedback)
        self.about_notepad.triggered.connect(self.get_about_note)

    def get_help(self):
        """获取帮助
        获取csdn 个人资料页面
        """
        help_url = "https://blog.csdn.net/weixin_72637522?type=blog"
        QDesktopServices.openUrl(help_url)

    def send_feedback(self):
        """发送反馈
        提交信息到gitee issue
        """
        send_url = "https://gitee.com/BasterHapy/pyside6_notepad_zero_one/issues"
        QDesktopServices.openUrl(send_url)

    def get_about_note(self):
        content = "使用PySide6实现的win10记事本\n作者：开心-开心急了"
        icon = QPixmap("./part9/images/notepad.png")
        aboutNotepad = QMessageBox(self)
        aboutNotepad.setIconPixmap(icon)
        aboutNotepad.setWindowTitle("关于记事本")
        aboutNotepad.setText(content)
        aboutNotepad.setStandardButtons(QMessageBox.StandardButton.Ok)
        aboutNotepad.show()
    